import java.util.Scanner;


/**
 * 
 * @author Group 202
 * 
 * Exercise 4.2
 *
 */

public class GGT_Berechnen {


	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		System.out.print("Bitte geben Sie die erste Zahl ein: ");
		int firstNumber = scanner.nextInt();
		System.out.print("Bitte geben Sie die zweite Zahl ein: ");
		int secondNumber = scanner.nextInt();
		
		int counter = 0;
		while(firstNumber != 0 && secondNumber != 0)
		{
			if(firstNumber % 2 == 0 && secondNumber % 2 == 0)
			{
				firstNumber /= 2;
				secondNumber /= 2;
				counter++;
			}
			else if(firstNumber % 2 == 0)
			{
				firstNumber /= 2;
			}
			else if(secondNumber % 2 == 0)
			{
				secondNumber /= 2;
			}
			else
			{
				if(firstNumber > secondNumber)
					firstNumber = (int) ((firstNumber - secondNumber) / 2);
				else
					secondNumber = (int) ((secondNumber - firstNumber) / 2);
			}
		}
		
		System.out.println(String.format("Der ggt ist %s", firstNumber != 0 
				? firstNumber * Math.pow(2, counter)
				: secondNumber * Math.pow(2, counter)));
	}

}
